package com.ssh.dates.dao;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.junit.Test;

import com.ssh.dates.model.DateTable;
import com.ssh.utils.DBConnection;

public class DateTimeOperation {
	@Test
	public void insert() {
		String sql = "insert into dateTable values (dateTable_id.nextval, " + 
						"to_date(?, 'yyyy-mm-dd'), " + 
						"to_date(?, 'yyyy-mm-dd hh24:mi:ss'), " + 
						"to_timestamp(?, 'yyyy-mm-dd hh24:mi:ss.ff'))";
		Date date = new Date();
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		
		int result = DBConnection.update(sql, new Object[] {sdf1.format(date),sdf2.format(date),sdf3.format(date)});
		System.out.println(result);
	}
	@Test
	public void select() {
		String sql = "select * from dateTable";
		List<DateTable> list = DBConnection.query(sql, DateTable.class, new Object[] {});
		list.forEach((item->System.out.println(item)));
	}
}
